<template>
  <header id="header2">
    <router-link to slot="left" class="back">
      <img src="../../../static/m_img/back.png" alt class @click="$router.back(-1)">
    </router-link>
    <Form action v-model="searchForm" class="search">
      <span class="selectCity" @click="handleCityShow">
        <i class="icon_xl">1</i>
        <b class="ellipsis-1">{{searchForm.city}}</b>
      </span>
      <Input placeholder="请输入内容" v-model="searchForm.keyWords">
        <i slot="prefix" class="el-input__icon el-icon-search"></i>
      </Input>
    </Form>
    <v-city
      :cityShow="cityShow"
      :title="title"
      ref="cityList"
      v-on:listenToChildEvent="showmsgformchild"
    ></v-city>
  </header>
</template>
<script>
import { Form, Input } from "element-ui";
import vCity from "./City";
export default {
  data() {
    return {
      searchForm: {
        keyWords: "",
        city: ""
      },
      cityShow: false,
      title: "选择车辆所在地"
    };
  },
  components: {
    Form,
    Input,
    vCity
  },
  props: {
    navIndex: {
      type: Number,
      require: true,
      default: 0
    }
  },
  methods: {
    handleCityShow() {
      this.cityShow = true;
    },
    showmsgformchild: function(data) {
      this.cityShow = data;
      if (
        this.$refs.cityList.curCityName == "" &&
        this.$refs.cityList.curProvinceName !== ""
      ) {
        this.searchForm.city = this.$refs.cityList.curProvinceName;
      } else if (this.$refs.cityList.curCityName !== "") {
        this.searchForm.city = this.$refs.cityList.curCityName;
      }
    }
  },
  created() {},
  mounted() {
    this.searchForm.city = getCookie("cityDw");
  }
};
</script>
<style type="text/css" lang='scss'>
#header2 {
  position: fixed;
  width: 100%;
  z-index: 9999;
  background: #fff;
  top:0px;
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 2%;
  .back {
    width: 9px;
    height: 17.5px;
  }
  .search {
    display: flex;
    margin-left: 5%;
    width: 80%;
    height: 31px;
    justify-content: space-between;
    align-items: center;
    .selectCity {
      display: flex;
      align-items: center;
      width: 20%;
      margin-right:2%;
      b {
        width: 78%;
        font-weight: normal;
      }
      .icon_xl {
        background: url(../../../static/m_img/z_dw.png) center center no-repeat;
        background-size: cover;
        text-indent: -999px;
        width: 17px;
        height: 17px;
        margin-right: 5px;
        display: inline-block;
      }
    }
    .el-input {
      width: 80%;
      font-size: 1rem;
      height: 31px;
      .el-input__inner {
        width: 100%;
        height: 31px;
        padding-left: 28px;
        color: #aaaaaa;
        border: 1px solid rgba(229, 229, 229, 1);
        border-radius: 2px;
      }
      .el-input__icon {
        line-height: 31px;
      }
      .el-icon-search:before {
        font-size: 1.166667rem;
        color: #aaaaaa;
      }
    }
  }
  img {
    height: 100%;
  }
}
</style>


